package Cantella::DJabberd::Web::UI::ViewPort::List;

use Reaction::Class;
extends 'Reaction::UI::ViewPort';

has item_class => (is => 'rw', isa => 'ClassName', lazy_fail => 1);
has items      => (is => 'ro', isa => 'ArrayRef', required => 1, default => sub{[]});

sub add_item {
  my ($self) = shift;
  my $items = $self->items;
  my $item  = $self->item_class->new
    ( ctx => $self->ctx,
      location => join('-', $self->location, scalar @$items),
      @_,
    );
  push(@$items, $item);
  return $item;
}

override child_event_sinks => sub {
  my $self = shift;
  return (@{ $self->items }, super());
};

__PACKAGE__->meta->make_immutable;

1;

__END__;
